<?php 
session_cache_expire(999999999);
if(!isset($_SESSION)) 
	{ 
		session_start(); 
	}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<?php
function getlang(){
		$lang = $_SESSION['lang'];
		if (empty($lang) || $lang == "EN") {
			$value = "../value/value_en.php";
		} else if($lang == "VN") {
			$value = "../value/value_vn.php";
		}
		else {
			$value = "../value/value_kr.php";
		}
		return $value;
	}
$value = getlang();
include($value);
$listpurchase =$_SESSION['listpurchase'];
#echo $_GET['action'];
if (isset($_GET['action'])){
	if($_GET['action']=='add'){
		$listpurchase =$_SESSION['listpurchase'];
		$listpurchase[]=array(0,"","",0,0,0,0);
	}
	if($_GET['action']=='del'){
		$listpurchase =$_SESSION['listpurchase'];
		$list=array();
		for($i=0;$i<count($listpurchase);$i++){	
				if($listpurchase[$i][0]==0){
					$list[]=$listpurchase[$i];
				}
		}
		$listpurchase=$list;
	}
	if($_GET['action']=='check'){
		$listpurchase =$_SESSION['listpurchase'];
		$id=$_GET['id'];
		for($i=0;$i<count($listpurchase);$i++){
			if ($i==($id-1)){
				$listpurchase[$i][0]=($listpurchase[$i][0]+1)%2;
			}
		}
	}
	
	if($_GET['action']=='chPrice'){
		$id=$_GET['id'];
		$listpurchase =$_SESSION['listpurchase'];
		for($i=0;$i<count($listpurchase);$i++){
			if ($i==($id-1)){
				$listpurchase[$i][4]=$_GET['value'];
			}
		}
	}
	if($_GET['action']=='chQuantity'){
		$id=$_GET['id'];
		$listpurchase =$_SESSION['listpurchase'];
		for($i=0;$i<count($listpurchase);$i++){
			if ($i==($id-1)){
				$listpurchase[$i][3]=$_GET['value'];
			}
		}
	}
	if($_GET['action']=='chName'){
		$id=$_GET['id'];
		$listpurchase =$_SESSION['listpurchase'];
		for($i=0;$i<count($listpurchase);$i++){
			if ($i==($id-1)){
				$listpurchase[$i][2]=$_GET['value'];
			}
		}
	}
	if($_GET['action']=='chItem'){
		$id=$_GET['id'];
		$listpurchase =$_SESSION['listpurchase'];
		for($i=0;$i<count($listpurchase);$i++){
			if ($i==($id-1)){
				$listpurchase[$i][1]=rawurldecode($_REQUEST['value']);
			}
		}
	}
}
?>
<body>	
	
				<?php 
				$i=1;
				$total=0;
				foreach ($listpurchase as $purchase){
					$total=$total+$purchase[6];
					$i=$i+1;
				}?>
		
	<input type="text" readonly="readonly"
					name="alltotalamount" value="<?=number_format($total)?>"
					style="height: 24px; width: 30%; border: 1px solid #c4c0c9" />
	
<?php $_SESSION['listpurchase']=$listpurchase;?>
</body>
</html>
